#include <myheader_c_plus.h>
using std::endl;
using std::cout;
template<class T, int kcapacity = 10>
class Stack{
public:
    //无参构造函数
    Stack()
    :_top(-1)
    ,_data(new T[kcapacity]())
    {
        cout << "Stack()" << endl;
    }


    //析构函数
    ~Stack(){
        if(_data){
            delete _data;
            _data = nullptr;
        }
        cout << "~Stack()" << endl;
    }

    bool empty() const{
        if(_top == -1){
            return true;
        }
        return false;
    }
    bool full() const{
        if(_top == kcapacity - 1){
            return true;
        }
        return false;
    }
    void push(const T & ele){
        if(!full()){
            //add elements
            _data[_top] = ele;
            ++_top;
            return;
        }
        cout << "the Stack is full now" << endl;
        return;
    }
    void pop(){
        if(!empty()){
            --_top;
            return;
        }
        cout << "stack is empty" << endl;
        return;

    }
    T top(){
        if(!empty()){
            return _data[_top];
        }
         cout << "the stack is empty" << endl;
         return (T)0;
    }



private:
    int _top;
    T * _data;
};
int main(int argc, char *argv[])
{
    Stack<double, 20> stack;
    cout << stack.top() << endl;
    stack.push(2.1);
    stack.push(4.5);

   cout <<  stack.top() << endl;
    stack.pop();
    cout << stack.top() << endl;
    cout << stack.empty() << endl;
    


    return 0;
}

